package com.entity

import com.DeleteObjectsRequestTypeConverter
import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion
import picocli.CommandLine.Command
import picocli.CommandLine.Option
import java.io.File
import java.util.concurrent.Callable

/**
 * 文档
 * https://picocli.info/#_add_as_external_dependency
 */
@Command(
    name = "aws",
    header = ["Version 2.0"],
    requiredOptionMarker = '*',
    abbreviateSynopsis = true,
    sortOptions = false
)
data class PackCmd(private val callable: (() -> Unit)? = null) : Callable<Int> {

    @Option(names = ["-help"], usageHelp = true, description = ["显示帮助并退出"])
    var help: Boolean = false

    @JvmField
    @Option(names = ["-cls", "-clear"], description = ["清理 CloudFront 缓存"])
    var clear: Boolean = false

    /** 打包类型 1 打包上传 2 创建桶 3 更改权限  */
    @Option(names = ["-t", "-type"], description = ["打包类型 1 打包上传 2 创建桶 3 更改权限"])
    var type: Int = 0

    /** 在公共账户信息文件中的别名  */
    @JvmField
    @Option(names = ["-n", "-name"], description = ["账户信息文件中的别名"])
    var profile: String? = null

    /** 登录钥匙  */
    @JvmField
    @Option(names = ["id", "accessKeyId"], description = ["账号id"])
    var accessKeyId: String? = null

    /** 登录钥匙密码  */
    @JvmField
    @Option(names = ["psd", "accessKeySecret"], description = ["密码"])
    var accessKeySecret: String? = null

    /** 桶名字  */
    @JvmField
    @Option(names = ["bname", "bucketName"], description = ["桶名字"])
    var bucketName: String? = null

    /** 上传服务器的根路径  */
    @JvmField
    @Option(names = ["rp", "rootPath"], description = ["上传服务器的根路径"])
    var rootPath: String? = null

    /** 父路径  */
    @JvmField
    @Option(names = ["p", "parent"], description = ["父路径"])
    var parentPath: String? = null

    /** 上传文件配置表  */
    @Option(names = ["-r", "-read"], description = ["上传文件配置表"])
    var uploadFileConfig: String? = null

    /** 需要打包到指定目录的文件  */
    @Option(names = ["-p", "-pack"], description = ["需要打包到指定目录的文件"])
    var uploadFilePackFile: String? = null

    /** 要上传的文件  */
    @JvmField
    @Option(names = ["add", "addFile"], description = ["要上传的文件"], split = ",")
    var uploadFileList: List<File>? = null

    /** 要删除的文件  */
    @JvmField
    @Option(
        names = ["rm", "deleteFile"],
        description = ["要删除的文件"],
        split = ",",
        converter = [DeleteObjectsRequestTypeConverter::class]
    )
    var deleteFileList: List<KeyVersion>? = null

    /** 要被清理服务器的id  */
    @JvmField
    @Option(
        names = ["dbId", "distributionId"],
        description = ["要被清理服务器的id,如果设置了此值，那么更新的时候不在去服务器获取桶id，推荐手动设置这样可以快速清理缓存"]
    )
    var distributionId: String? = null

    override fun call(): Int? {
        callable?.invoke()
        return null
    }

}